#include "texcoords.h"

texcoords::texcoords()
{
	U = 0.0;
	V = 0.0;
}
texcoords::texcoords(double u, double v)
{
	U = u;
	V = v;
}
texcoords::~texcoords()
{

}
void texcoords::getTexCoordsFromXML(std::ifstream &file)
{
	char line[MAX_LENGTH];
	file.getline(line, MAX_LENGTH);
	std::string nazwaWezla;
	std::string temp(line);

	unsigned int i(0);

	while(temp[i] == 9 || temp[i] == 32)
		++i;

	++i;
	while(temp[i] != '>')
	{
		nazwaWezla.push_back(temp[i]);
		++i;
	}
	while (nazwaWezla!="/texcoord")
	{
		file.getline(line, MAX_LENGTH);
		temp.clear();
		temp.append(line);
		nazwaWezla.clear();

		i=0;
		while(temp[i] == 9 || temp[i] == 32)
			++i;
		if(temp[i] == '<')
		{
			std::string nazwaWezlaKoniec;
			std::string zawartoscWezla;
			++i;
			while(temp[i] != '>')
			{
				nazwaWezla.push_back(temp[i]);
				++i;
			}
			if(nazwaWezla == "U")
			{
				++i;
				while(temp[i] != '<')
				{
					zawartoscWezla.push_back(temp[i]);
					++i;
				}
				++i;
				while(temp[i] != '>')
				{
					nazwaWezlaKoniec.push_back(temp[i]);
					++i;
				}
				if(nazwaWezlaKoniec == "/U")
					this->U = atof(zawartoscWezla.c_str());
				continue;
			}
			else if(nazwaWezla == "V")
			{
				++i;
				while(temp[i] != '<')
				{
					zawartoscWezla.push_back(temp[i]);
					++i;
				}
				++i;
				while(temp[i] != '>')
				{
					nazwaWezlaKoniec.push_back(temp[i]);
					++i;
				}
				if(nazwaWezlaKoniec == "/V")
					this->V = atof(zawartoscWezla.c_str());
				continue;
			}
		}
	}
}
void texcoords::setTexCoords(double u, double v)
{
	U = u;
	V = v;
}
double texcoords::getU()
{
	return U;
}
double texcoords::getV()
{
	return V;
}